/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {Thrift} from '@ohos/thrift'
import CalculatorClient from '../../common/calculator/Calculator';
import {WorkSet, WorkMap, WorkList, Operation
} from '../../common/calculator/tutorial_types';

export default {
    data: {
        mapSize: '',
        listSize: '',
        setSize: '',
    },
    onInit() {
    },
    onButtonClick() {
        var transport = new Thrift.Transport("http://192.168.0.109:9090/thrift/service/tutorial/");
        var protocol = new Thrift.Protocol(transport);
        var client = new CalculatorClient(protocol);

        var that = this;

        var workMap = new WorkMap()
        workMap.mapValue = {
            'hello': 'world', 'OpenHarmony': 'thrift'
        };
        workMap.op = Operation.MAP_SIZE;
        client.getMapSize(1, workMap, function (result) {
            if (result) {
                that.mapSize = result;
            }
        });

        var workSet = new WorkSet()
        workSet.setValue = ['hello', 'world'];
        workSet.op = Operation.SET_SIZE;
        client.getSetSize(1, workSet, function (result) {
            if (result) {
                that.setSize = result;
            }
        });

        var workList = new WorkList()
        workList.listValue = ['hello', 'world'];
        workList.op = Operation.LIST_SIZE;
        client.getListSize(1, workList, function (result) {
            if (result) {
                that.listSize = result;
            }
        });
    }
}
